<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Docker 搭建 DNMP 环境 | AiKIKI</title><meta name="author" content="樵子"><meta name="copyright" content="樵子"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="referrer" content="no-referrer"><meta name="description" content="Linxu 下搭建 Nginx、PHP 和 MariaDB 称之为 LNMP，那么我们在 Docker 下搭建就叫 DNMP 吧（虽然我不知道这样叫是否正确）。 配置单机网桥由于这几个镜像相互之间需要通信，最好的解决方案是创建一个容器网络。因此我们首先需要创建 Docker 网络 localnet，用于 docker 之间的通信。 12345# Linux$ docker network crea">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 搭建 DNMP 环境">
<meta property="og:url" content="https://www.aikiki.top/post/6f9d/index.html">
<meta property="og:site_name" content="AiKIKI">
<meta property="og:description" content="Linxu 下搭建 Nginx、PHP 和 MariaDB 称之为 LNMP，那么我们在 Docker 下搭建就叫 DNMP 吧（虽然我不知道这样叫是否正确）。 配置单机网桥由于这几个镜像相互之间需要通信，最好的解决方案是创建一个容器网络。因此我们首先需要创建 Docker 网络 localnet，用于 docker 之间的通信。 12345# Linux$ docker network crea">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif">
<meta property="article:published_time" content="2020-03-22T08:13:00.000Z">
<meta property="article:modified_time" content="2023-11-16T08:35:20.000Z">
<meta property="article:author" content="樵子">
<meta property="article:tag" content="MariaDB">
<meta property="article:tag" content="PHP">
<meta property="article:tag" content="phpMyAdmin">
<meta property="article:tag" content="Nginx">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif"><link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/favicon.ico"><link rel="canonical" href="https://www.aikiki.top/post/6f9d/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Docker 搭建 DNMP 环境',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-16 16:35:20'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 7.0.0"><link rel="alternate" href="/atom.xml" title="AiKIKI" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/avatar.png" onerror="onerror=null;src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">21</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">1</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif')"><nav id="nav"><span id="blog-info"><a href="/" title="AiKIKI"><span class="site-name">AiKIKI</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Docker 搭建 DNMP 环境</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-03-22T08:13:00.000Z" title="发表于 2020-03-22 16:13:00">2020-03-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-11-16T08:35:20.000Z" title="更新于 2023-11-16 16:35:20">2023-11-16</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Archives/">Archives</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Docker 搭建 DNMP 环境"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>Linxu 下搭建 Nginx、PHP 和 MariaDB 称之为 <code>LNMP</code>，那么我们在 Docker 下搭建就叫 <code>DNMP</code> 吧（虽然我不知道这样叫是否正确）。</p>
<h1 id="配置单机网桥"><a href="#配置单机网桥" class="headerlink" title="配置单机网桥"></a>配置单机网桥</h1><p>由于这几个镜像相互之间需要通信，最好的解决方案是创建一个容器网络。<br>因此我们首先需要创建 Docker 网络 <code>localnet</code>，用于 docker 之间的通信。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># Linux</span><br><span class="line">$ docker network create -d bridge localnet</span><br><span class="line"></span><br><span class="line"># Windows</span><br><span class="line">&gt; docker network create -d nat localnet</span><br></pre></td></tr></table></figure>

<p>查看创建好的网络。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ docker network list</span><br><span class="line">NETWORK ID          NAME                DRIVER              SCOPE</span><br><span class="line">b7228b827811        bridge              bridge              <span class="built_in">local</span></span><br><span class="line">af39f057ff30        host                host                <span class="built_in">local</span></span><br><span class="line"></span><br><span class="line">363014e0c45c        localnet            bridge              <span class="built_in">local</span></span><br><span class="line"></span><br><span class="line">007b2a216146        none                null                <span class="built_in">local</span></span><br></pre></td></tr></table></figure>

<p>NAME 为 <code>localnet</code> 的网络即为新建的网络，后续创建的 Docker 容器就将加入该网络中。</p>
<h1 id="安装-php7"><a href="#安装-php7" class="headerlink" title="安装 php7"></a>安装 <code>php7</code></h1><h2 id="下载-php7-镜像"><a href="#下载-php7-镜像" class="headerlink" title="下载 php7 镜像"></a>下载 <code>php7</code> 镜像</h2><p>php 有很多版本，我们可以在 <a target="_blank" rel="noopener" href="https://hub.docker.com/">官方仓库</a> 搜索自己需要的镜像。<br>找到需要的镜像后，首先下载镜像：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker pull php:7.4.4-fpm</span><br></pre></td></tr></table></figure>

<blockquote>
<p>这里以 <code>php:7.4.4-fpm</code> 为例。</p>
</blockquote>
<p>镜像是否下载成功，可以通过以下指令确认。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ docker images</span><br><span class="line">REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE</span><br><span class="line">php                 7.4.4-fpm           7d64b9cd1388        2 days ago          405MB</span><br></pre></td></tr></table></figure>

<h2 id="安装-php7-镜像到容器"><a href="#安装-php7-镜像到容器" class="headerlink" title="安装 php7 镜像到容器"></a>安装 <code>php7</code> 镜像到容器</h2><p>现在可以将镜像运行到容器中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name php7 --network localnet -v /home/&lt;your-username&gt;/docker/nginx/www/html:/var/www/html --restart=always php:7.4.4-fpm</span><br></pre></td></tr></table></figure>

<blockquote>
<p>参数说明：</p>
<ul>
<li><code>&lt;your-username&gt;</code> 表示系统用户名 <code>我习惯将 docker 相关文件放在默认用户名下面便于备份(下同)</code></li>
<li>-d <code>后台方式运行</code></li>
<li>–name php7 <code>容器名称</code></li>
<li>–network localnet <code>加入到网络 localnet 中</code></li>
<li>–restart&#x3D;always <code>系统重启后自动运行</code></li>
<li>–privileged&#x3D;true <code>应用容器获取宿主机 root 权限</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;nginx&#x2F;www&#x2F;html:&#x2F;var&#x2F;www&#x2F;html <code>将 nginx 的网站根目录(宿主机目录)映射到 php7 容器的网站根目录</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;php&#x2F;<a target="_blank" rel="noopener" href="http://www.conf/usr/local/etc/php-fpm.d/www.conf">www.conf:/usr/local/etc/php-fpm.d/www.conf</a> <code>php 的配置文件映射（可选）</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;php&#x2F;log:&#x2F;var&#x2F;log <code>日志目录映射（可选）</code><br>php7 需要使用 9000 端口提供给 nginx 使用，由于使用了 docker 容器网络 localnet 在容器之间通信，因此这里就不需要再将 9000 端口映射到宿主机。</li>
</ul>
</blockquote>
<p>容器运行成功，可以执行以下指令查看运行情况：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ docker ps -a</span><br><span class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES</span><br><span class="line"></span><br><span class="line">10d9826eef99        php:7.4.4-fpm       <span class="string">&quot;docker-php-entrypoi…&quot;</span>   4 seconds ago       Up 4 seconds        9000/tcp            php7</span><br></pre></td></tr></table></figure>

<h2 id="安装-mysqli-扩展"><a href="#安装-mysqli-扩展" class="headerlink" title="安装 mysqli 扩展"></a>安装 <code>mysqli</code> 扩展</h2><p>php 默认不安装 <code>mysqli</code> 扩展，我们需要手动安装。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"># 进入容器</span><br><span class="line">$ docker exec -ti &lt;your-php-container&gt; /bin/bash</span><br><span class="line"></span><br><span class="line"># 安装 mysqli 扩展</span><br><span class="line"></span><br><span class="line">&gt;&gt; docker-php-ext-install mysqli</span><br><span class="line"></span><br><span class="line">#  安装 pdo 和 pdo_mysql (可选)</span><br><span class="line"></span><br><span class="line">&gt;&gt; docker-php-ext-install pdo pdo_mysql</span><br><span class="line"></span><br><span class="line"># 国外网站找到的参考资料，还需要做以下两步，实测不需要。这里做个记录备忘。</span><br><span class="line"></span><br><span class="line"># 执行第一步会提示：warning: mysqli (mysqli.so) is already loaded!</span><br><span class="line"></span><br><span class="line"># 执行第二步会提示：bash: apachectl: command not found</span><br><span class="line"></span><br><span class="line">&gt;&gt; docker-php-ext-enable mysqli</span><br><span class="line"></span><br><span class="line">&gt;&gt; apachectl restart</span><br></pre></td></tr></table></figure>

<blockquote>
<p><code>&lt;your-php-container&gt;</code> 表示容器名称。</p>
</blockquote>
<p>安装成功后，退出容器，然后重启容器即可。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 退出容器</span><br><span class="line">$ exit</span><br><span class="line"></span><br><span class="line"># 重启容器</span><br><span class="line">$ docker restart &lt;your-php-container&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>有的扩展不用重启，自己试试即可。</p>
</blockquote>
<h1 id="安装-nginx"><a href="#安装-nginx" class="headerlink" title="安装 nginx"></a>安装 <code>nginx</code></h1><h2 id="下载-nginx-镜像"><a href="#下载-nginx-镜像" class="headerlink" title="下载 nginx 镜像"></a>下载 <code>nginx</code> 镜像</h2><p>nginx 可以使用以下指令直接下载镜像，默认下载最新版。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker pull nginx</span><br></pre></td></tr></table></figure>

<p>下载完成后，检查一下下载镜像。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ docker images</span><br><span class="line">REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE</span><br><span class="line">php                 7.4.4-fpm           7d64b9cd1388        2 days ago          405MB</span><br><span class="line">nginx               latest              6678c7c2e56c        2 weeks ago         127MB</span><br></pre></td></tr></table></figure>

<h2 id="安装-nginx-镜像到容器"><a href="#安装-nginx-镜像到容器" class="headerlink" title="安装 nginx 镜像到容器"></a>安装 <code>nginx</code> 镜像到容器</h2><p>执行以下指令将镜像运行到容器中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name nginx --network localnet -p 80:80 -p 443:443 -v /home/&lt;your-username&gt;/docker/nginx/etc/nginx:/etc/nginx -v /home/&lt;your-username&gt;/docker/nginx/www/html:/usr/share/nginx/html -v /home/&lt;your-username&gt;/docker/nginx/logs:/var/log/nginx --restart=always nginx</span><br></pre></td></tr></table></figure>

<blockquote>
<p>参数说明</p>
<ul>
<li>-d <code>后台执行</code></li>
<li>–name nginx <code>容器名称</code></li>
<li>–network localnet <code>加入到网络 localnet 中</code></li>
<li>–restart&#x3D;always <code>系统重启后自动运行</code></li>
<li>–privileged&#x3D;true <code>应用容器获取宿主机 root 权限</code></li>
<li>-p 80:80 <code>映射 80 端口到宿主机</code></li>
<li>-p 443:443 <code>映射 443 端口到宿主机</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;nginx&#x2F;etc&#x2F;nginx:&#x2F;etc&#x2F;nginx <code>映射 nginx 配置文件夹</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;nginx&#x2F;www&#x2F;html:&#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html <code>映射 nginx 网站根路径</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;nginx&#x2F;logs:&#x2F;var&#x2F;log&#x2F;nginx <code>映射日志文件夹</code></li>
</ul>
</blockquote>
<h2 id="配置-nginx-支持-php"><a href="#配置-nginx-支持-php" class="headerlink" title="配置 nginx 支持 php"></a>配置 <code>nginx</code> 支持 <code>php</code></h2><h3 id="从容器中复制默认配置文件"><a href="#从容器中复制默认配置文件" class="headerlink" title="从容器中复制默认配置文件"></a>从容器中复制默认配置文件</h3><p>如果没有 nginx 的<code>配置文件</code>，可以暂不映射配置文件夹，先把容器临时跑起后，从容器中将配置文件复制出来后，再删除容器重新安装。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment"># 从容器中复制文件, nginx 是容器名称，“:”号后面是要复制的路径，最后是要目的路径。</span></span><br><span class="line">$ docker <span class="built_in">cp</span> nginx:/etc/nginx ./</span><br></pre></td></tr></table></figure>

<h3 id="修改-php-配置"><a href="#修改-php-配置" class="headerlink" title="修改 php 配置"></a>修改 <code>php</code> 配置</h3><p>修改宿主机中的 nginx 配置文件，本文地址是：<code>/home/&lt;your-username&gt;/docker/nginx/etc/nginx</code><br>在配置文件中增加或者修改 <code>php</code> 解析配置如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">  location ~ \.php$ &#123;</span><br><span class="line"></span><br><span class="line">try_files      $uri = 404;</span><br><span class="line">      fastcgi_pass   php7:9000;</span><br><span class="line">      fastcgi_param  SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;</span><br><span class="line">      include        fastcgi_params;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意两个参数：</p>
<ul>
<li>php7 <code>这是 php 容器的名字，nginx 通过该名字访问 php 容器。</code></li>
<li>&#x2F;var&#x2F;www&#x2F;html&#x2F; <code>这是 php 容器中的网站根路径（不是宿主机路径）</code></li>
</ul>
</blockquote>
<h2 id="测试-nginx"><a href="#测试-nginx" class="headerlink" title="测试 nginx"></a>测试 <code>nginx</code></h2><h3 id="查看容器运行"><a href="#查看容器运行" class="headerlink" title="查看容器运行"></a>查看容器运行</h3><p>容器运行成功，执行以下指令查看运行情况：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ docker ps -a</span><br><span class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                      NAMES</span><br><span class="line">fa527e2f7b17        nginx               <span class="string">&quot;nginx -g &#x27;daemon of…&quot;</span>   6 seconds ago       Up 5 seconds        0.0.0.0:80-&gt;80/tcp, 0.0.0.0:443-&gt;443/tcp   nginx</span><br><span class="line"></span><br><span class="line">10d9826eef99        php:7.4.4-fpm       <span class="string">&quot;docker-php-entrypoi…&quot;</span>   3 hours ago         Up 33 minutes       9000/tcp                                   php7</span><br></pre></td></tr></table></figure>

<h3 id="测试-www-服务"><a href="#测试-www-服务" class="headerlink" title="测试 www 服务"></a>测试 www 服务</h3><p>现在你可以输入 <code>宿主机的 ip 地址</code> 来测试你的网站。<br>在此之前别忘了在网站根目录放入测试网页：index.html。</p>
<h3 id="测试-php-服务"><a href="#测试-php-服务" class="headerlink" title="测试 php 服务"></a>测试 <code>php</code> 服务</h3><p>在网站根目录新建 php 测试文件：<code>phpinfo.php</code>，并输入以下内容：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;?</span><br><span class="line">phpinfo();</span><br><span class="line"></span><br><span class="line">?&gt;</span><br></pre></td></tr></table></figure>

<p>在浏览器输入该文件地址进行测试，正常会显示 PHP 相关信息。</p>
<h2 id="设置网站根目录所有权权限"><a href="#设置网站根目录所有权权限" class="headerlink" title="设置网站根目录所有权权限"></a>设置网站根目录所有权权限</h2><p>现在 nginx 已经正常运行，但是遇见网站程序要写入硬盘的时候，系统会提示文件夹没有写入权限。<br>那么，我们需要到容器中设置网站根目录的所有权（当然，你也可以设置到需要写入权限的文件夹上）。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 进入容器</span><br><span class="line">$ docker exec -it nginx /bin/bash</span><br><span class="line"></span><br><span class="line"># 进入 nginx 目录</span><br><span class="line">$ cd /usr/share/nginx</span><br><span class="line"></span><br><span class="line"># 设置网站根目录所有权为  www-data</span><br><span class="line">$ chown -R www-data:www-data ./</span><br></pre></td></tr></table></figure>

<blockquote>
<p>docker 中运行的 nginx 和 php 都是以 www-data 身份运行的。</p>
</blockquote>
<h1 id="安装-mariadb"><a href="#安装-mariadb" class="headerlink" title="安装 mariadb"></a>安装 <code>mariadb</code></h1><h2 id="下载-mariadb-镜像"><a href="#下载-mariadb-镜像" class="headerlink" title="下载 mariadb 镜像"></a>下载 <code>mariadb</code> 镜像</h2><p>mariadb 也可以使用以下指令直接下载镜像，默认下载最新版。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker pull mariadb</span><br></pre></td></tr></table></figure>

<p>下载完成后，检查一下下载镜像。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ docker images</span><br><span class="line">REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE</span><br><span class="line">mariadb             latest              37f5f0a258bf        41 hours ago        356MB</span><br><span class="line">php                 7.4.4-fpm           7d64b9cd1388        2 days ago          405MB</span><br><span class="line">nginx               latest              6678c7c2e56c        2 weeks ago         127MB</span><br></pre></td></tr></table></figure>

<h2 id="安装-mariadb-镜像到容器"><a href="#安装-mariadb-镜像到容器" class="headerlink" title="安装 mariadb 镜像到容器"></a>安装 <code>mariadb</code> 镜像到容器</h2><p>执行以下指令将镜像运行到容器中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name mariadb  --network localnet -e MYSQL_ROOT_PASSWORD=rootpassword -e MYSQL_USER=username -e MYSQL_PASSWORD=userpassword -v /home/&lt;your-username&gt;/docker/mariadb/data:/var/lib/mysql --restart=always mariadb --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci</span><br></pre></td></tr></table></figure>

<blockquote>
<p>参数说明</p>
<ul>
<li>-d <code>后台执行</code></li>
<li>–name mariadb <code>容器名称（注意：php 程序配置数据库地址，请填入该名称）</code></li>
<li>–network localnet <code>加入到网络 localnet 中</code></li>
<li>–restart&#x3D;always <code>系统重启后自动运行</code></li>
<li>–privileged&#x3D;true <code>应用容器获取宿主机 root 权限</code></li>
<li>-p 3306:3306 <code>映射 3360 端口到宿主机（如不提供外网访问，可不映射）</code></li>
<li>-e MYSQL_ROOT_PASSWORD&#x3D;rootpassword <code>root 密码</code></li>
<li>-e MYSQL_USER&#x3D;username <code>创建普通用户名</code></li>
<li>-e MYSQL_PASSWORD&#x3D;userpassword <code>创建用户的密码</code></li>
<li>-v &#x2F;home&#x2F;&lt;your-username&gt;&#x2F;docker&#x2F;mariadb&#x2F;data:&#x2F;var&#x2F;lib&#x2F;mysql <code>库文件保存路径映射</code></li>
<li>–character-set-server&#x3D;utf8mb4 <code>字符集（一定要放在参数的末尾）</code></li>
<li>–collation-server&#x3D;utf8mb4_unicode_ci <code>字符集（一定要放在参数的末尾）</code></li>
</ul>
</blockquote>
<p>成功运行，查看容器运行情况。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ docker ps -a</span><br><span class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                      NAMES</span><br><span class="line"></span><br><span class="line">6df4e2434b29        mariadb             <span class="string">&quot;docker-entrypoint.s…&quot;</span>   6 seconds ago       Up 5 seconds        3306/tcp                                   mariadb</span><br><span class="line">fa527e2f7b17        nginx               <span class="string">&quot;nginx -g &#x27;daemon of…&quot;</span>   46 minutes ago      Up 46 minutes       0.0.0.0:80-&gt;80/tcp, 0.0.0.0:443-&gt;443/tcp   nginx</span><br><span class="line"></span><br><span class="line">10d9826eef99        php:7.4.4-fpm       <span class="string">&quot;docker-php-entrypoi…&quot;</span>   4 hours ago         Up About an hour    9000/tcp                                   php7</span><br></pre></td></tr></table></figure>

<h1 id="安装-phpMyAdmin"><a href="#安装-phpMyAdmin" class="headerlink" title="安装 phpMyAdmin"></a>安装 <code>phpMyAdmin</code></h1><h2 id="下载和安装-phpMyAdmin"><a href="#下载和安装-phpMyAdmin" class="headerlink" title="下载和安装 phpMyAdmin"></a>下载和安装 phpMyAdmin</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 进入 nginx 根目录</span><br><span class="line">cd /home/&lt;your-username&gt;/docker/nginx/www/html</span><br><span class="line"></span><br><span class="line"># 下载 phpMyAdmin 压缩文件</span><br><span class="line">wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz -O phpMyAdmin.tar.gz</span><br><span class="line"></span><br><span class="line"># 解压缩</span><br><span class="line">tar xzvf phpMyAdmin.tar.gz</span><br><span class="line"></span><br><span class="line"># 重命名文件夹，源文件夹名称请根据实际情况修改</span><br><span class="line">mv phpMyAdmin-4.8.5-all-languages phpMyAdmin</span><br><span class="line"></span><br><span class="line"># 删除压缩文件</span><br><span class="line">rm phpMyAdmin.tar.gz</span><br></pre></td></tr></table></figure>

<h2 id="配置-phpMyAdmin"><a href="#配置-phpMyAdmin" class="headerlink" title="配置 phpMyAdmin"></a>配置 phpMyAdmin</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 进入 phpMyAdmin 目录</span><br><span class="line">cd phpMyAdmin</span><br><span class="line"></span><br><span class="line"># 创建 phpMyAdmin 配置文件</span><br><span class="line">cp config.sample.inc.php config.inc.php</span><br><span class="line"></span><br><span class="line"># 编辑配置文件</span><br><span class="line">vim config.inc.php</span><br></pre></td></tr></table></figure>

<p>修改以下配置信息：</p>
<p>设置 32 位长度的加密密码。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;blowfish_secret&#x27;</span>] = <span class="string">&#x27;abcdefghijklmnopqrstuvwxyz123456&#x27;</span>;</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>点击 <a target="_blank" rel="noopener" href="https://passgen.co/?pw=32&sy=0">这里</a> 生成 32 位长度密码。</p>
</blockquote>
<p>设置服务器名称：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;host&#x27;</span>] = <span class="string">&#x27;databasename&#x27;</span>;</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>数据名称是 MariaDB 的容器名称，本示例中是 <code>mariadb</code>。</p>
</blockquote>
<p>开启高级功能：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;pmadb&#x27;</span>] = <span class="string">&#x27;phpmyadmin&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;bookmarktable&#x27;</span>] = <span class="string">&#x27;pma__bookmark&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;relation&#x27;</span>] = <span class="string">&#x27;pma__relation&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;table_info&#x27;</span>] = <span class="string">&#x27;pma__table_info&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;table_coords&#x27;</span>] = <span class="string">&#x27;pma__table_coords&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;pdf_pages&#x27;</span>] = <span class="string">&#x27;pma__pdf_pages&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;column_info&#x27;</span>] = <span class="string">&#x27;pma__column_info&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;history&#x27;</span>] = <span class="string">&#x27;pma__history&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;table_uiprefs&#x27;</span>] = <span class="string">&#x27;pma__table_uiprefs&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;tracking&#x27;</span>] = <span class="string">&#x27;pma__tracking&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;userconfig&#x27;</span>] = <span class="string">&#x27;pma__userconfig&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;recent&#x27;</span>] = <span class="string">&#x27;pma__recent&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;favorite&#x27;</span>] = <span class="string">&#x27;pma__favorite&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;users&#x27;</span>] = <span class="string">&#x27;pma__users&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;usergroups&#x27;</span>] = <span class="string">&#x27;pma__usergroups&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;navigationhiding&#x27;</span>] = <span class="string">&#x27;pma__navigationhiding&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;savedsearches&#x27;</span>] = <span class="string">&#x27;pma__savedsearches&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;central_columns&#x27;</span>] = <span class="string">&#x27;pma__central_columns&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;designer_settings&#x27;</span>] = <span class="string">&#x27;pma__designer_settings&#x27;</span>;</span></span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">cfg[<span class="string">&#x27;Servers&#x27;</span>][<span class="variable">$i</span>][<span class="string">&#x27;export_templates&#x27;</span>] = <span class="string">&#x27;pma__export_templates&#x27;</span>;</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>将前面的注释代码去掉即可。</p>
</blockquote>
<h2 id="配置-cfg-‘TempDir’-权限"><a href="#配置-cfg-‘TempDir’-权限" class="headerlink" title="配置 $cfg[‘TempDir’] 权限"></a>配置 $cfg[‘TempDir’] 权限</h2><p>phpMyAdmin 为了提高性能需要写入临时文件，配置临时目录如下。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 进入容器</span><br><span class="line">$ docker exec -it nginx /bin/bash</span><br><span class="line"></span><br><span class="line"># 进入 nginx 目录</span><br><span class="line">$ cd /usr/share/nginx/www/phpMyAdmin</span><br><span class="line"></span><br><span class="line"># 新建文件夹 tmp</span><br><span class="line">mkdir tmp</span><br><span class="line"></span><br><span class="line"># 设置文件夹所有权</span><br><span class="line">chown -R www-data:www-data tmp</span><br><span class="line"></span><br><span class="line"># 设置文件夹读写权限</span><br><span class="line">chmod -R 700 tmp</span><br></pre></td></tr></table></figure>

<blockquote>
<p>文件夹的所有权如果再 nginx 配置阶段已经设置，这里可忽略。<br>只需要检查写入权限即可。</p>
</blockquote>
<h2 id="登录-phpMyAdmin"><a href="#登录-phpMyAdmin" class="headerlink" title="登录 phpMyAdmin"></a>登录 phpMyAdmin</h2><p>现在你可以输入 phpMyAdmin 的地址访问你的数据库了。</p>
<p>首次登录系统会提示一个错误信息：<br><code>phpMyAdmin 高级功能尚未完全设置，部分功能未激活。查找原因。</code></p>
<p>点击后面的查找原因，按提示创建数据库 phpMyAdmin 即可。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://www.aikiki.top">樵子</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://www.aikiki.top/post/6f9d/">https://www.aikiki.top/post/6f9d/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.aikiki.top" target="_blank">AiKIKI</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/MariaDB/">MariaDB</a><a class="post-meta__tags" href="/tags/PHP/">PHP</a><a class="post-meta__tags" href="/tags/phpMyAdmin/">phpMyAdmin</a><a class="post-meta__tags" href="/tags/Nginx/">Nginx</a><a class="post-meta__tags" href="/tags/Docker/">Docker</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/f10f/" title="给 Docker 中的 PHP 安装 GD 扩展"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif" onerror="onerror=null;src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">给 Docker 中的 PHP 安装 GD 扩展</div></div></a></div><div class="next-post pull-right"><a href="/post/fed3/" title="Debian 10 安装 Docker-CE"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/debian-logo-horizontal.jfif" onerror="onerror=null;src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Debian 10 安装 Docker-CE</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/52e3/" title="CentOS 7 搭建 LNMP 环境"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/centos-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-26</div><div class="title">CentOS 7 搭建 LNMP 环境</div></div></a></div><div><a href="/post/e4e5/" title="CentOS 7 搭建 LAMP 环境安装 WordPress"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/centos-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-10</div><div class="title">CentOS 7 搭建 LAMP 环境安装 WordPress</div></div></a></div><div><a href="/post/f10f/" title="给 Docker 中的 PHP 安装 GD 扩展"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-25</div><div class="title">给 Docker 中的 PHP 安装 GD 扩展</div></div></a></div><div><a href="/post/fed3/" title="Debian 10 安装 Docker-CE"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/debian-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-22</div><div class="title">Debian 10 安装 Docker-CE</div></div></a></div><div><a href="/post/ea01/" title="CentOS 8 安装 Docker-CE"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/centos-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-23</div><div class="title">CentOS 8 安装 Docker-CE</div></div></a></div><div><a href="/post/872e/" title="Rocky Linux 8 安装 Docker-CE"><img class="cover" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/rockylinux-logo-horizontal.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-07-14</div><div class="title">Rocky Linux 8 安装 Docker-CE</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/avatar.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">樵子</div><div class="author-info__description">Always CREATIVE.</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">21</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">1</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/acmeist"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/acmeist" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:huweighost@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="Rss"><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">感謝訪問本站，若喜歡請收藏 ^_^</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E5%8D%95%E6%9C%BA%E7%BD%91%E6%A1%A5"><span class="toc-number">1.</span> <span class="toc-text">配置单机网桥</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-php7"><span class="toc-number">2.</span> <span class="toc-text">安装 php7</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD-php7-%E9%95%9C%E5%83%8F"><span class="toc-number">2.1.</span> <span class="toc-text">下载 php7 镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-php7-%E9%95%9C%E5%83%8F%E5%88%B0%E5%AE%B9%E5%99%A8"><span class="toc-number">2.2.</span> <span class="toc-text">安装 php7 镜像到容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-mysqli-%E6%89%A9%E5%B1%95"><span class="toc-number">2.3.</span> <span class="toc-text">安装 mysqli 扩展</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-nginx"><span class="toc-number">3.</span> <span class="toc-text">安装 nginx</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD-nginx-%E9%95%9C%E5%83%8F"><span class="toc-number">3.1.</span> <span class="toc-text">下载 nginx 镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-nginx-%E9%95%9C%E5%83%8F%E5%88%B0%E5%AE%B9%E5%99%A8"><span class="toc-number">3.2.</span> <span class="toc-text">安装 nginx 镜像到容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-nginx-%E6%94%AF%E6%8C%81-php"><span class="toc-number">3.3.</span> <span class="toc-text">配置 nginx 支持 php</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E5%AE%B9%E5%99%A8%E4%B8%AD%E5%A4%8D%E5%88%B6%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">3.3.1.</span> <span class="toc-text">从容器中复制默认配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9-php-%E9%85%8D%E7%BD%AE"><span class="toc-number">3.3.2.</span> <span class="toc-text">修改 php 配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95-nginx"><span class="toc-number">3.4.</span> <span class="toc-text">测试 nginx</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E8%BF%90%E8%A1%8C"><span class="toc-number">3.4.1.</span> <span class="toc-text">查看容器运行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95-www-%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.4.2.</span> <span class="toc-text">测试 www 服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95-php-%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.4.3.</span> <span class="toc-text">测试 php 服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E7%BD%91%E7%AB%99%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%89%80%E6%9C%89%E6%9D%83%E6%9D%83%E9%99%90"><span class="toc-number">3.5.</span> <span class="toc-text">设置网站根目录所有权权限</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-mariadb"><span class="toc-number">4.</span> <span class="toc-text">安装 mariadb</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD-mariadb-%E9%95%9C%E5%83%8F"><span class="toc-number">4.1.</span> <span class="toc-text">下载 mariadb 镜像</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-mariadb-%E9%95%9C%E5%83%8F%E5%88%B0%E5%AE%B9%E5%99%A8"><span class="toc-number">4.2.</span> <span class="toc-text">安装 mariadb 镜像到容器</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-phpMyAdmin"><span class="toc-number">5.</span> <span class="toc-text">安装 phpMyAdmin</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E5%92%8C%E5%AE%89%E8%A3%85-phpMyAdmin"><span class="toc-number">5.1.</span> <span class="toc-text">下载和安装 phpMyAdmin</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-phpMyAdmin"><span class="toc-number">5.2.</span> <span class="toc-text">配置 phpMyAdmin</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-cfg-%E2%80%98TempDir%E2%80%99-%E6%9D%83%E9%99%90"><span class="toc-number">5.3.</span> <span class="toc-text">配置 $cfg[‘TempDir’] 权限</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%99%BB%E5%BD%95-phpMyAdmin"><span class="toc-number">5.4.</span> <span class="toc-text">登录 phpMyAdmin</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/c3b4/" title="Docker 使用宿主机网段"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/docker-logo-horizontal.jfif" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="Docker 使用宿主机网段"/></a><div class="content"><a class="title" href="/post/c3b4/" title="Docker 使用宿主机网段">Docker 使用宿主机网段</a><time datetime="2023-12-18T01:27:00.000Z" title="发表于 2023-12-18 09:27:00">2023-12-18</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/1e36/" title="ESXi 远程 SSH 终端登录显示器管理界面"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/esxi-logo-horizontal.jfif" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="ESXi 远程 SSH 终端登录显示器管理界面"/></a><div class="content"><a class="title" href="/post/1e36/" title="ESXi 远程 SSH 终端登录显示器管理界面">ESXi 远程 SSH 终端登录显示器管理界面</a><time datetime="2023-11-29T01:45:00.000Z" title="发表于 2023-11-29 09:45:00">2023-11-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/9973/" title="ESXi 6.7 自动关机设置"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/esxi-logo-horizontal.jfif" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="ESXi 6.7 自动关机设置"/></a><div class="content"><a class="title" href="/post/9973/" title="ESXi 6.7 自动关机设置">ESXi 6.7 自动关机设置</a><time datetime="2023-11-25T07:12:00.000Z" title="发表于 2023-11-25 15:12:00">2023-11-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/bf0c/" title="OpenWrt 安装自带 Tailscale 和 ZeroTier"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/openwrt-logo-horizontal.jfif" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="OpenWrt 安装自带 Tailscale 和 ZeroTier"/></a><div class="content"><a class="title" href="/post/bf0c/" title="OpenWrt 安装自带 Tailscale 和 ZeroTier">OpenWrt 安装自带 Tailscale 和 ZeroTier</a><time datetime="2023-11-21T01:19:00.000Z" title="发表于 2023-11-21 09:19:00">2023-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/53a7/" title="OpenWrt 更新所有已安装软件包"><img src="https://cdn.jsdelivr.net/gh/acmeist/CDN/logos/openwrt-logo-horizontal.jfif" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/404.jpg'" alt="OpenWrt 更新所有已安装软件包"/></a><div class="content"><a class="title" href="/post/53a7/" title="OpenWrt 更新所有已安装软件包">OpenWrt 更新所有已安装软件包</a><time datetime="2023-11-15T01:38:00.000Z" title="发表于 2023-11-15 09:38:00">2023-11-15</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 樵子</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/"><img class="icp-icon" src="https://cdn.jsdelivr.net/gh/acmeist/CDN/www/img/icp.png"><span>渝ICP备19007019号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>